#include "main.h"

using namespace std;


bool MakeSocketNonBlocking(INT32 iSock)
{
    INT32 flag = fcntl( iSock, F_GETFL, 0);
    if( -1 == flag ) {
        printf("fcntl get error=%s" , strerror( errno ));
        return -1;
    }
    flag |= O_NONBLOCK;
    if( fcntl( iSock, F_SETFL, flag ) == -1 ) {
        printf("fcntl get error=%s" , strerror( errno ));
        return -1;
    }

    return 0;
}
INT32 SocketReuseAddr(INT32 i_sock_fd, bool b_reuse)
{
    int mode = b_reuse?1:0;
    if( i_sock_fd != -1 ) {
        return setsockopt(i_sock_fd,SOL_SOCKET,SO_REUSEADDR,(void *)&mode,sizeof(int));
    }
    return -1;
}

INT32 sys_time_getms_r(struct timeval &st_init_time, struct timeval &st_now_time, INT64 *pll_sys_ms_time)
{
    INT64 temp = 0;

    gettimeofday(&st_now_time, NULL);

    temp = (INT64)(st_now_time.tv_sec) * (INT64)1000 + (INT64)(st_now_time.tv_usec) / (INT64)1000 - (INT64)st_init_time.tv_sec * (INT64)1000 - (INT64)st_init_time.tv_usec / (INT64)1000;
    *pll_sys_ms_time = temp;

    return 0;
}

int main ()
{
    if (0) {
        tcp_srv();
    } else {
        udp_srv();
    }
    return 0;
}

